package com.qdlc.p2p.dal.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.qdlc.p2p.dal.common.model.jpa.PageDataList;
import com.qdlc.p2p.dal.dao.CardRuleDao;
import com.qdlc.p2p.dal.dto.CardRule;
import com.qdlc.p2p.dal.model.CardRuleModel;
import com.qdlc.p2p.dal.mybatis.model.mapper.CardRuleMapper;
import com.qdlc.p2p.dal.mybatis.pager.PageProxyBuilder;
import com.qdlc.p2p.dal.mybatis.pager.core.PageParameter;

/**
 * 卡片规则信息Dao实现类
 *
 * @author Kaiju Zhao
 * @version V1.0.0
 * @date 2016-05-06
 */
@Repository("cardRuleDao")
public class CardRuleDaoImpl implements CardRuleDao {

    @Resource
    private CardRuleMapper cardRuleMapper;

    @Override
    public void save(CardRule cardRule) {
        cardRuleMapper.insert(cardRule);
    }

    @Override
    public void delete(long id) {
        cardRuleMapper.delete(id);
    }

    @Override
    public int update(CardRule cardRule) {
        return cardRuleMapper.update(cardRule);
    }

    @Override
    public int update(int status, int preStatus, long id) {
        return cardRuleMapper.updateStatus(status, preStatus, id);
    }

    @Override
    public CardRule findById(long id) {
        return cardRuleMapper.findById(id);
    }

    @Override
    public List<CardRule> findUsableCardRules() {
        return cardRuleMapper.findUsableCardRules();
    }

    @Override
    public PageDataList<CardRule> list(CardRuleModel model) {
        PageProxyBuilder<CardRuleMapper> builder = PageProxyBuilder.newBuilder(CardRuleMapper.class);
        builder.setPageParameter(model.getPage(), model.getRows());
        List<CardRule> list = builder.createProxy().list(model);
        PageParameter page = builder.getPageParameter();
        return new PageDataList<CardRule>(page.convert2Page(), list);
    }

    @Override
    public int existCardRule(long id, int type, int status) {
        return cardRuleMapper.existCardRule(id, type, status);
    }

}
